<?php
namespace app\index\controller;
header("content-type:text/html;charset=utf-8");

use think\Db;
use think\Controller;

class Uploads extends Controller
{
    /**
     * @return string
     */
    public function index(){
        echo rand(1000000, 9999999);;die;
        return $this->fetch('index');
        print_r($_FILES);
    }
    // 文件上传提交
     public function upload(){

//         echo $path;die;
//         echo $time=intval(time());die;
//         print_r($_FILES['file']['name']);die;
             // 获取表单上传文件
         $file = request()->file('file');
//         print_r($file);die;
         if (empty($file)) {
                    $this->error('请选择上传文件');
         }
         $path = intval(time()).rand(1000000, 9999999).$_FILES['file']['name'];
         // 移动到框架应用根目录/public/uploads/ 目录下
         $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads',$path);
//         echo ROOT_PATH . 'public' . DS . 'uploads/'.$path;die;

         if ($info) {
             echo 'http://localhost/tp5/public/uploads/'.$path;
//             echo $info->getFilename();
         } else {
                     // 上传失败获取错误信息
             $this->error($file->getError());
         }

     }
}
